
<template>
<el-upload
  class="upload-demo"
  drag
  :action="action"
  :on-success="success"
  :file-list="fileList"
  :on-preview="handlePreview"
  multiple>
  <i class="el-icon-upload"></i>
  <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
</el-upload>
</template>
<script>
import { baseUrl } from "@/config/env";
const urls = {
    upload: baseUrl + "/zweixin/upload",
    upload_file:baseUrl + "/zweixin/fk/bl/upload_file",
    download:baseUrl + "/zweixin/download",
    get_file:baseUrl + "/zweixin/fk/bl/get_file",
}
  export default {
    data() {
      return {
        fileList: [],
        action:urls.upload,
      };
    },
    // props:['kid'],
    mounted(){
        //  axios.get(urls.get_file, {params:{"kid":this.kid}}).then(res => {
        //      console.log(res);
        //      var name = res.data.result.file_name;
        //      var url = urls.download+"/"+res.data.result.kid;
        //      this.fileList.push({name:name,url:url});
        //   });
    },
    methods: {
        handleRemove(file, fileList) {
            console.log(file, fileList);
        },
        handlePreview(file) {
            window.location.href = file.url;
        },
        success(response, file, fileList){
            this.fileList = [];
            var name = response.name;
            var url = this.download +"/"+response.file_id;
             this.fileList.push({name:name,url:url});
            var params = {};
            params.file_id = response.file_id;
            params.kid = this.kid;
        },
        handleExceed(files, fileList) {
            this.$message.warning(`当前限制选择 3 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`);
        },
        beforeRemove(file, fileList) {
            return this.$confirm(`确定移除 ${ file.name }？`);
        }
    }
  }
</script>